package com.yonxao.demo.crud.annotation.valid;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;

/**
 * 校验字符串是否是 JSON 字符串
 * <p>
 * 自定义校验注解，需指定校验器，可以指定多个
 *
 * @author xiaosaguo
 * @date 2020/09/21
 */
@Documented
@Constraint(validatedBy = {IsJsonConstraintValidator.class})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
public @interface IsJson {

    String message() default "不是一个合法的 JSON 字符串";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}
